home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn-1.4-l / inn-1 / inn-1.4-linux-0.1 / bash-patches / bash-1.12-fd3.diff next >
Text File  |  1993-08-22  |  2KB  |  60 lines

  1. I found it (we had fixed this a few months back, which is why it's not
  2. reproducible in current development versions).  Your gdb guy was close,
  3. but was looking at the wrong thing.  He is correct in that gdb manages
  4. something differently from dbx, but that thing is file descriptors, not
  5. memory.)
  6.  
  7. Bash uses file descriptor 3 for reading the script, because that's the
  8. file descriptor returned by open.  When the Configure script uses the
  9. `exec 3>&1' construct, the bash code doesn't know how to handle it,
  10. because stdio doesn't allow swapping file descriptors associated with
  11. FILEs.  Bash does ahead and does the dup2, duplicating fd 1 onto fd 3.
  12. The stdio FILE still has file descriptor 3 associated with it,
  13. and tries to read from it, which results in the script attempting to
  14. read from stdout when it goes back for more of the script. 
  15.  
  16. I have appended a patch with code from the current development version
  17. of 1.13 that fixes this.
  18.  
  19. sh and ksh have always done something like this with the script fd,
  20. moving it to a file descriptor out of the user-accessible range (which
  21. has traditionally been 0-9).  The bash problem is harder, since
  22. Posix.2 says that all file descriptors are user-accessible (e.g.,
  23. 10>/dev/null redirects file descriptor 10, rather than file descriptor
  24. 0 as sh and ksh do).  There are no descriptors that are `off-limits'
  25. to the user, so this patch adds a dup2 to getdtablesize() - 1 and hopes
  26. for the best. 
  27.  
  28. The original 1.12 code worked in gdb because gdb uses fd 3 for its own
  29. purposes, so it is open when bash is run, and therefore not used when
  30. bash opens the script file.  (The file descriptor returned by the open
  31. is 5, in my case.) This leaves file descriptor 3 free for use by the
  32. `exec'. 
  33.  
  34. *** shell.c.orig    Tue Jan 21 00:52:37 1992
  35. --- shell.c    Thu Feb 25 07:39:09 1993
  36. ***************
  37. *** 706,709 ****
  38. --- 706,720 ----
  39.       }
  40.   
  41. +       {
  42. +     int script_fd;
  43. +     script_fd = dup2 (fd, getdtablesize () - 1);
  44. +     if (script_fd)
  45. +       {
  46. +         close (fd);
  47. +         fd = script_fd;
  48. +       }
  49. +       }
  50.         default_input = fdopen (fd, "r");
  51.   
  52.  
  53. --
  54. ``The use of history as therapy means the corruption of history as history.''
  55.     -- Arthur Schlesinger
  56.  
  57. Chet Ramey, Case Western Reserve University    Internet: chet@po.CWRU.Edu
  58.